/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.dao;

import br.com.deployment.daogenerico.DaoGenerico;
import br.com.deployment.entidade.empresa.Fornecedor;
import br.com.deployment.interfaces.FornecedorDaoIn;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author luciano
 */
@Stateless
@LocalBean
public class FornecedorDao extends DaoGenerico<Fornecedor> implements FornecedorDaoIn{

    public FornecedorDao() {
        super(Fornecedor.class);
    }
    
    public List<Fornecedor> findFornecedor(Fornecedor fornecedor) {
        List<Fornecedor> listCor = new ArrayList<Fornecedor>();
        if (fornecedor != null) {
            String sql = "Select f from Fornecedor f where ";

            if (fornecedor.getNome() != null && fornecedor.getNome() != "") {
                sql += " lower(f.nome) like lower(?1) and ";
            }
            sql += " 1 = 1;";
            Query query = getEm().createQuery(sql);
            if (fornecedor.getNome() != null && fornecedor.getNome() != "") {
                query.setParameter("1", "%" + fornecedor.getNome() + "%");
            }
            

            listCor = query.getResultList();
            System.out.println(sql);
        }

        return listCor;
    }
    
    
}
